import java.util.Random;
import java.util.Scanner;

public class RandomSelector {
    public static void main(String[] args) {
        Student[] students = new Student[100];
        int studentCount = 0;
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入学生信息（以输入'结束'表示完成输入）：");
        while (true) {
            System.out.print("学生姓名：");
            String name = scanner.nextLine();
            if ("结束".equals(name)) {
                break;
            }
            System.out.print("学生班级：");
            String studentClass = scanner.nextLine();
            System.out.print("学生学号：");
            int studentId = scanner.nextInt();
            System.out.print("小组编号：");
            int groupId = scanner.nextInt();
            scanner.nextLine(); // 处理换行符

            students[studentCount] = new Student(name, studentClass, studentId, groupId);
            studentCount++;
        }

        System.out.println("选择选取方式：");
        System.out.println("1. 随机选取学生");
        System.out.println("2. 随机选取小组");

        int choice = scanner.nextInt();
        Random random = new Random();
        if (choice == 1) {
            int randomIndex = random.nextInt(studentCount);
            Student randomStudent = students[randomIndex];
            System.out.println("随机选取的学生信息：");
            System.out.println("姓名：" + randomStudent.getName());
            System.out.println("班级：" + randomStudent.getStudentClass());
            System.out.println("学号：" + randomStudent.getStudentId());
            System.out.println("小组编号：" + randomStudent.getGroupId());
        } else if (choice == 2) {
            int[] uniqueGroupIds = new int[100];
            int uniqueCount = 0;
            for (int i = 0; i < studentCount; i++) {
                boolean isUnique = true;
                for (int j = 0; j < uniqueCount; j++) {
                    if (students[i].getGroupId() == uniqueGroupIds[j]) {
                        isUnique = false;
                        break;
                    }
                }
                if (isUnique) {
                    uniqueGroupIds[uniqueCount++] = students[i].getGroupId();
                }
            }
            int randomGroupIndex = random.nextInt(uniqueCount);
            int randomGroupId = uniqueGroupIds[randomGroupIndex];
            System.out.println("随机选取的小组编号：" + randomGroupId);
        } else {
            System.out.println("无效选择。");
        }
    }
}